/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Controller;

import Database.Koneksi;
import Model.Member;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
//import org.apache.jasper.tagplugins.jstl.core.Catch;

/**
 *
 * @author Dion
 */
public class Login {
    public String cek(String nama, String passw) throws SQLException {
        String hasil1 = "error error";
        Connection con = Koneksi.open();
        String jdbcUrl = "jdbc:oracle:thin:@localhost:1521:XE";
        String name = "HR";
        String pass = "suryo115314";
        String id ="";

        Statement stat = (Statement) con.createStatement();
        String query = "select * from GUDANG";
        ResultSet hasil = stat.executeQuery(query);
        while (hasil.next()) {
            name = hasil.getString(1);
            pass = hasil.getString(2);

            if (nama.equals(name) && passw.equals(pass)) {
                hasil1 = nama + " Gudang";
            }

        }
        if (hasil1.equals("error error")) {
            query = "select * from MEMBER";
            hasil = stat.executeQuery(query);
            while (hasil.next()) {
                name = hasil.getString(2);
                pass = hasil.getString("PASSWORD");
                System.out.println(nama+" "+name+"rrrrrrrrrrrrrrrr"+pass);
                if (nama.equals(name) && pass.equals("123456")) {
                    hasil1 = nama + " Edit";
                } else {
                    if (name.equals(nama) && passw.equals(pass)) {
                        id=hasil.getString(1);
                        hasil1 = id + " Toko";
                    }
                }
            }
        }
        return hasil1;
    }

    public boolean update(String email, String password) throws SQLException {
       // Login logg = new Login();
        //String hasil2 = "error error";
        boolean hasil = false;
        int has = 0;
      //  String[] dataArray = email.split("/");
        Connection con = Koneksi.open();
        Statement st = null;
        ResultSet rs = null;
        try {
            Member mem = new Member();
         //   String username = mem.getEmail();
            Statement stat = (Statement) con.createStatement();
            String sql = "update MEMBER set PASSWORD= '"+password+"' where EMAIL='"+email+"'";
            System.out.println("PAS"+password+"mail="+email);
          //  String query = " insert into BARANG values(?,?,?)";
            PreparedStatement statement = con.prepareStatement(sql);
           // statement.setString(1, dataArray[0]);
          //  statement.setString(2, dataArray[1]);
            has = statement.executeUpdate();
            con.commit();
        } catch (SQLException ex) {
            Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
        }
        if (has > 0) {
            hasil = true;
        }
        return hasil;
    }     
}